<div class="span9">
    <div class="control-group">
        <label class="">Tipo Despesa</label>
        <div class="controls">
            <select name="data[AccountsExpense][expense_id]" id="sa-select-expense_id" class="span12">
                <option value="">SELECIONE</option>
                <?php foreach($expenses as $expense): ?>
                    <option value="<?php echo $expense['Expense']['id'] ?>"><?php echo $expense['Expense']['name'] ?></option>
                <?php endforeach ?>
            </select>
        </div>
    </div>
</div>
<div class="span3">
    <div class="control-group">
        <label class="">Valor a Pagar</label>
        <div class="controls">
            <input type="text" name="data[AccountsExpense][value]" id="sa-input-valorItemDespesa" placeholder="XXX,XX" class="span12 text-center"/>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $('#sa-input-valorItemDespesa').keyup(function(){
            var valorItemDespesa = $(this).val();
            var newValorItemDespesa = valorItemDespesa.replace(/[\D]+/g,'');
            newValorItemDespesa = newValorItemDespesa.replace(/([0-9]{2})$/g,',$1');
            if(newValorItemDespesa.length > 6)
            {
                newValorItemDespesa = newValorItemDespesa.replace(/([0-9]{3}),([0-9]{2})$/g,'.$1,$2');
            }
            $(this).val(newValorItemDespesa);
        });
    });
</script>